﻿-- =============================================
-- Author:		<Author,XFL>
-- Create date: <Create Date,20111230>
-- Description:	<Description,--获取固定补助 总数>
-- =============================================
CREATE PROCEDURE [dbo].[proc_Employee_FixedAllowance_GetList_BackUp]
(
	@CompanyId int,
	@EName nvarchar(50),
	@StartIndex int,
	@EndIndex int
)
AS
BEGIN
		;WITH list As(Select ROW_NUMBER() OVER 
(
ORDER BY 
--按金额排序 
(Select Count(Id)	From Employee_FixedAllowance	Where (@CompanyId = 0 Or CompanyId=@CompanyId) and (@EName Is Null Or EName like '%'+@EName+'%'))
desc)AS Row,
		 Id
		,CompanyId
		,(Select c.CompanyName From Company c Where c.Id=CompanyId) as CompanyName
		,DepartmentId
		,(Select d.DName From Department d Where d.Id=DepartmentId) as DepartmentName
		,UserName
		,EName
		,Amount
		,Memo
		,CreateDate
--记录数
--		,(Select Count(Id)	From Employee_FixedAllowance	Where (@CompanyId = 0 Or CompanyId=@CompanyId) and (@EName Is Null Or EName like '%'+@EName+'%')) AS Sum_Count
		From 
			Employee_FixedAllowance 
		Where
			(@CompanyId = 0 Or CompanyId=@CompanyId)
			and (@EName Is Null Or EName like '%'+@EName+'%')
		)
		Select *,(select count(0) from list ) AS Sum_Count  From list Where Row between @StartIndex and @EndIndex 
END
